package com.sofwin.controller;

import com.sofwin.ResponseEntity;
import com.sofwin.pojo.SysResource;
import com.sofwin.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.xml.ws.Response;
import java.util.List;

/**
 * @packageName: com.sofwin.controller
 * @user: andyliu
 * @date: 2023/1/3 11:24
 * @email 115176513@qq.com
 * @description: TODO
 */
@Controller
@RequestMapping("resource")
public class ResourceController {
    @Autowired
    private ResourceService resourceService;

    @GetMapping
    public String toList(){
        return "resource/list";
    }
    // 获取到的是所有的资源
    @PostMapping("data")
    @ResponseBody
    public ResponseEntity data(SysResource resource){
        List<SysResource> resources = resourceService.queryResources(resource);
        return ResponseEntity.success(resources);
    }
    // 获取所有的资源，如果该角色有当前资源的权限，增加checked属性为true
    @GetMapping("treeData")
    @ResponseBody
    public ResponseEntity treeData(Integer roleId){
        List<SysResource> resources = resourceService.queryResourceByRoleId(roleId);
        return ResponseEntity.success(resources);
    }
}
